<?php
include_once ('class/autoload.php');
require_once ('connexLicence.php');

$requete = 'Select id from praticiens';
$result = $connexion->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	$requete = 'DELETE FROM praticiens WHERE id = ' . $OneRow->id . ';';
	$result2 = $connexion->query ( $requete );
}

$requete = 'Select id from cabinet';
$result = $connexion->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	if ($OneRow->id != 0) {
		$requete = 'DELETE FROM cabinet WHERE id = ' . $OneRow->id . ';';
		$result2 = $connexion->query ( $requete );
	}
}
$requete = 'Select * from cabinet';
$result = $connexion->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	
	$requete = 'DELETE FROM telephone;';
	$result2 = $connexion->query ( $requete );
}

$requete = 'Select id, Nom, Telephone from cabinet';
$result = $connexion2->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	$requete = 'INSERT INTO cabinet VALUES("' . $OneRow->id . '","' . $OneRow->Nom . '","' . $OneRow->Telephone . '");';
	$connexion->query ( $requete );
}

$requete = 'Select * from praticiens';
$result = $connexion2->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	$requete = 'INSERT INTO praticiens VALUES ("' . $OneRow->id . '","' . $OneRow->idCabinet . '","' . $OneRow->nom . '","' . $OneRow->prenom . '","' . $OneRow->date_fin . '")';
	$result2 = $connexion->query ( $requete );
}

$requete = 'SELECT * FROM praticiens AS p INNER JOIN cabinet AS c on p.idCabinet = c.id';
$result = $connexion2->query ( $requete );
$result->setFetchMode ( PDO::FETCH_OBJ );
while ( $OneRow = $result->fetch () ) {
	$requete = 'INSERT INTO telephone VALUES("' . $OneRow->id . '","' . str_replace ( " ", "", $OneRow->Telephone ) . '");';
	$connexion->query ( $requete );
}

include_once 'AccueilConnecter.php';
 